//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.controller;

import com.example.common.Result;
import com.example.entity.Department;
import com.example.service.DepartmentService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping({"/department"})
public class DepartmentController {
    @Resource
    private DepartmentService departmentService;

    public DepartmentController() {
    }

    @GetMapping({"/selectAll"})
    public Result selectAll(Department department) {
        List<Department> list = this.departmentService.selectAll(department);
        return Result.success(list);
    }

    @GetMapping({"/selectById/{id}"})
    public Result selectById(@PathVariable Integer id) {
        Department department = this.departmentService.selectById(id);
        return Result.success(department);
    }

    @GetMapping({"/selectByOne"})
    public Result selectByOne(@RequestParam Integer id, @RequestParam(required = false) String no) {
        Department department = this.departmentService.selectById(id);
        return Result.success(department);
    }

    @GetMapping({"/selectList"})
    public Result selectList(Department department) {
        List<Department> list = this.departmentService.selectList(department);
        return Result.success(list);
    }

    @GetMapping({"/selectPage"})
    public Result selectPage(Department department, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Department> pageInfo = this.departmentService.selectPage(department, pageNum, pageSize);
        return Result.success(pageInfo);
    }

    @PostMapping({"/add"})
    public Result add(@RequestBody Department department) {
        this.departmentService.add(department);
        return Result.success();
    }

    @PutMapping({"/updateById"})
    public Result updateById(@RequestBody Department department) {
        this.departmentService.updateById(department);
        return Result.success();
    }

    @DeleteMapping({"/deleteById/{id}"})
    public Result deleteById(@PathVariable Integer id) {
        this.departmentService.deleteById(id);
        return Result.success();
    }

    @DeleteMapping({"/deleteBatch"})
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        this.departmentService.deleteBatch(ids);
        return Result.success();
    }
}
